package com.fhz.day003;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;

import android.os.Bundle;
import android.widget.Toast;

import com.fhz.day003.databinding.ActivityMainBinding;
import com.fhz.day003.index.Banner;
import com.fhz.day003.index.IndexViewModel;
import com.fhz.day003.index.IndexViewModelFactory;
import com.fhz.day003.mvvm.BaseMVVMActivity;
import com.fhz.day003.room.AppDatabase;
import com.fhz.day003.room.StudentDao;
import com.fhz.day003.room.User;
import com.fhz.day003.room.UserDao;
import com.fhz.day003.utils.ApiResponse;

import java.util.List;

public class MainActivity extends BaseMVVMActivity<IndexViewModel, ActivityMainBinding> {


    @Override
    protected void init() {

        UserDao userDao = AppDatabase.getInstance().userDao();

        User user = new User();
        user.firstName ="xiao";
        user.lastName = "ming";
        userDao.insertAll(user);

        List<User> all = userDao.getAll();

        StudentDao studentDao = AppDatabase.getInstance().studentDao();

//        studentDao.insert();

        Toast.makeText(this, ""+all.size(), Toast.LENGTH_SHORT).show();


        mViewModel.getBanner().observe(this, new Observer<ApiResponse<List<Banner>>>() {
            @Override
            public void onChanged(ApiResponse<List<Banner>> listApiResponse) {
                binding.setBanner(listApiResponse.data.get(1));
            }
        });
    }

    @Override
    protected IndexViewModel createViewModel() {
        return new ViewModelProvider(this,new IndexViewModelFactory()).get(IndexViewModel.class);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_main;
    }
}